<?php
include('connection/connection.php');
 $distId=$_REQUEST['distId'];
 $file1=$_REQUEST['fl'];
 $file = "$file1.csv";
  header("Content-Disposition: attachment; filename=$file");
	//header("Content-Type:application/vnd.ms-excel");
  header("Content-Type:application/octet-stream");
  if($file1=='tbl_dtls_q3_loc')
  {
  $querystring="select * from ".$file1." where district_id=".$distId."";
  }
  else
  {
  $querystring="SELECT * FROM ".$file1." where loc_id in(select id from tbl_dtls_q3_loc where district_id=".$distId.")";
   }
  $result_csv=mysql_query($querystring);
  $flag = false;
while(false !== ($r1=mysql_fetch_assoc($result_csv)))
{
if(!$flag) {
echo implode(",", array_keys($r1)) . "\n";
$flag = true;
}
echo implode(",", array_values($r1))."\n" ;
}

?>
